class Solution
{
public:
    vector<string> ans;
    string now;
    void dfs(int left_num, int right_num, int n)
    {
        if (left_num == n && right_num == n)
        {
            ans.push_back(now);
            return;
        }
        if (left_num < n)
        {
            now.push_back('(');
            dfs(left_num + 1, right_num, n);
            now.pop_back();
        }
        if (right_num < left_num)
        {
            now.push_back(')');
            dfs(left_num, right_num + 1, n);
            now.pop_back();
        }
    }
    vector<string> generateParenthesis(int n)
    {
        // 需要时刻满足左括号的数量一定要大于等于右括号的数量
        if (!n)
            return {};
        dfs(0, 0, n);
        return ans;
    }
};